package 类与对象.接口;

public class 接口的多态 {
    //接口的多态体现
    public static void main(String[] args) {
        IF i1 = new Monster(); //接口类型的变量i，可以指向实现了IF接口的类的实例对象
        i1 = new car();
        System.out.println(IF.n2);

        //多态数组 -> 接口类型数组
        Usb[] usbs = new Usb[2];
        Phone phone = new Phone();

        Camera camera = new Camera();
        camera.demo();
        usbs[0] = phone;
        usbs[1] = camera;

        for (int i = 0; i < usbs.length; i++) {
            usbs[i].usb();
            if(usbs[i] instanceof Phone){
                ((Phone) usbs[i]).call();
            }
        }
    }

}
interface IF{
    int n2 = 4;
}
class Monster implements IF{}
class car implements IF{}

interface Usb{
    int n1 = 2;
    public void usb();
};
class Phone implements Usb{
    public void call(){
        System.out.println("手机call");
    }

    @Override
    public void usb() {
        System.out.println("手机工作中");
    }
}

class BB{
    public void demo(){
        System.out.println("Recursion01");
    }
}
class Camera  extends BB implements Usb{
    @Override
    public void usb() {
        int n1 = Usb.n1;
        System.out.println("相机工作中" + Usb.n1);
    }
}


